|
|
|
|
|
|
|
Case Multiply
lblOperation = "X"
Case Divide
lblOperation = "/"
End Select
txtResult = ""
End Property |
|
|
|
|
|
|
|
|
In Listing 15.2, in addition to changing the property procedures to use the OpType type, you also add code to update lblCaption and clear txtResult when the operation type changes. Using Enums in this manner is just one way to make your control more robust. Figure 15.6 shows how the Operation property looks in the Properties window for a control instance. |
|
|
|
|
|
|
|
|
Figure 15.6
The Operation property
provides a list of valid values rather
than requiring the users to know them. |
|
|
|
|
|
|
|
|
Coding Methods and Events |
|
|
|
|
|
|
|
|
The ValidateEntries method determines whether users have typed valid numeric data into the two text boxes. It is a simple function that returns True or False. The code for this function is shown in Listing 15.3. |
|
|
|
|
|
|
|
|
Listing 15.3 CALC.ZIPThe ValidateEntries Method |
|
|
|
|
|
|
|
|
Public Function ValidateEntries() As Boolean
'Assume entries are invalid
ValidateEntries = False
'Check for Empty Strings
If Trim$(txtNum1) = "" Or Trim$(txtNum2) = "" Then Exit Function
'Check for Numeric values
If Not IsNumeric(txtNum1) Then Exit Function
If Not IsNumeric(txtNum2) Then Exit Function |
|
|
|
|
|